package com.audaque.springboot.foshanupload.web.webdemo.model.bo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zgb
 * @desc
 * @date 2023-06-05 22:54:53
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TreeNodeBo {
    private int id;
    private int parentId;
    private int level;
    private String value;
    private Boolean check = false;
    private List<TreeNodeBo> children = new ArrayList<>();

    public TreeNodeBo(int id) {
        this.id = id;
    }

    public void addChild(TreeNodeBo child) {
        this.children.add(child);
    }


    public static TreeNodeBo initTree() {
        int rootParentId=-1;
        TreeNodeBo root = new TreeNodeBo();
        root.id = 0;
        try {
            root.parentId = rootParentId;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        root.level = 0;
        root.value = "root";
        root.children = new ArrayList<>();

        TreeNodeBo node1 = new TreeNodeBo();
        node1.id = 1;
        node1.parentId = 0;
        node1.level = 1;
        node1.value = "node1";
        node1.children = new ArrayList<>();
        root.children.add(node1);

        TreeNodeBo node2 = new TreeNodeBo();
        node2.id = 2;
        node2.parentId = 0;
        node2.level = 1;
        node2.value = "node2";
        node2.children = new ArrayList<>();
        root.children.add(node2);

        TreeNodeBo node11 = new TreeNodeBo();
        node11.id = 3;
        node11.parentId = 1;
        node11.level = 2;
        node11.value = "node11";
        node11.children = new ArrayList<>();
        node1.children.add(node11);

        TreeNodeBo node12 = new TreeNodeBo();
        node12.id = 4;
        node12.parentId = 1;
        node12.level = 2;
        node12.value = "node12";
        node12.children = new ArrayList<>();
        node1.children.add(node12);

        TreeNodeBo node21 = new TreeNodeBo();
        node21.id = 5;
        node21.parentId = 2;
        node21.level = 2;
        node21.value = "node21";
        node21.children = new ArrayList<>();
        node2.children.add(node21);

        TreeNodeBo node22 = new TreeNodeBo();
        node22.id = 6;
        node22.parentId = 2;
        node22.level = 2;
        node22.value = "node22";
        node22.children = new ArrayList<>();
        node2.children.add(node22);

        TreeNodeBo node111 = new TreeNodeBo();
        node111.id = 7;
        node111.parentId = 3;
        node111.level = 3;
        node111.value = "node111";
        node111.children = new ArrayList<>();
        node11.children.add(node111);

        return root;

    }
}
